#include<string>  
#include<vector>  
#include<map>  
#include<algorithm>  
#include <unordered_map>  
  
using namespace std;  
class Solution
{
public:
    int romanToInt(string s)
    {
        unordered_map<char, int> romanValues = {
            {'I', 1},
            {'V', 5},
            {'X', 10},
            {'L', 50},
            {'C', 100},
            {'D', 500},
            {'M', 1000}};

        int result = 0;
        int prevValue = 0;

        for (int i = s.length() - 1; i >= 0; i--)
        {
            int currentValue = romanValues[s[i]];
            if (currentValue < prevValue)
            {
                result -= currentValue;
            }
            else
            {
                result += currentValue;
            }
            prevValue = currentValue;
        }

        return result;
    }
};
#ifndef COMPILER_ONLINE  
#include"header.cpp"  
#endif  
  
void Test1() {  
    int ret = Solution().romanToInt("III");  
    if (ret == 3) {  
        cout << "通过了用例1,测试III通过....OK!" << endl;  
    } else {  
        cout << "没有通过用例1,测试III失败....ERROR!" << endl;  
    }  
}  
  
void Test2() {  
    int ret = Solution().romanToInt("IV");  
    if (ret == 4) {  
        cout << "通过了用例2,测试IV通过....OK!" << endl;  
    } else {  
        cout << "没有通过用例2,测试IV失败....ERROR!" << endl;  
    }  
}  
  
void Test3() {  
    int ret = Solution().romanToInt("IX");  
    if (ret == 9) {  
        cout << "通过了用例3,测试IX通过....OK!" << endl;  
    } else {  
        cout << "没有通过用例3,测试IX失败....ERROR!" << endl;  
    }  
}  
  
void Test4() {  
    int ret = Solution().romanToInt("LVIII");  
    if (ret == 58) {  
        cout << "通过了用例4,测试LVIII通过....OK!" << endl;  
    } else {  
        cout << "没有通过用例4,测试LVIII失败....ERROR!" << endl;  
    }  
}  
  
void Test5() {  
    int ret = Solution().romanToInt("MCMXCIV");  
    if (ret == 1994) {  
        cout << "通过了用例5,测试MCMXCIV通过....OK!" << endl;  
    } else {  
        cout << "没有通过用例5,测试MCMXCIV失败....ERROR!" << endl;  
    }  
}  
  
void Test6() {  
    int ret = Solution().romanToInt("MCMIV");  
    if (ret == 1904) {  
        cout << "通过了用例6,测试MCMIV通过....OK!" << endl;  
    } else {  
        cout << "没有通过用例6,测试MCMIV失败....ERROR!" << endl;  
    }  
}  
  
void Test7() {  
    int ret = Solution().romanToInt("DCXXI");  
    if (ret == 621) {  
        cout << "通过了用例7,测试DCXXI通过....OK!" << endl;  
    } else {  
        cout << "没有通过用例7,测试DCXXI失败....ERROR!" << endl;  
    }  
}  
  
int main() {  
    Test1();  
    Test2();  
    Test3();  
    Test4();  
    Test5();  
    Test6();  
    Test7();  
    return 0;  
}